const validate = require('../../utils/validate')
const common = require('../../utils/common')
const { getShopProdStaticCount } = require('../../services/stores')
const dayjs = require('../../utils/dayjs')

Page({
  data: {
    date: dayjs().format('MM月DD日'),
    myShopStatics: {},
    dataList: [],
    loaded: false,
  },
  onLoad: function () {
    this.getDataList()
  },
  getDataList: function () {
    getShopProdStaticCount().then(res => {
      const { date, myShopStatics, shopProdStaticsList } = res.data
      this.setData({
        date: dayjs(date).format('MM月DD日'),
        myShopStatics,
        dataList: shopProdStaticsList,
        loaded: true
      })
    }).catch(err => {
      common.log(err)
    })
  },
  onCopy: function (e) {
    const dataList = this.data.dataList
    const timeDate = dayjs().format('MM-DD')
    const coypList = dataList.map(v => {
      return `
      ${timeDate} ${v.title}
      销量：${v.orderCount}件
      销售金额：¥${v.orderAmount.toFixed(2)}
      提成金额：¥${v.commissionAmount.toFixed(2)}
      `
    })
    if (!coypList || coypList.length <= 0) {
      common.showToast("无可复制内容")
      return
    }
    const copyText = coypList.join("")
    wx.setClipboardData({
      data: copyText,
      fail(res) {
        common.showToast("复制失败")
      }
    })
  }
})